home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8124 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  54 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!eskimo!scs
  3. From: scs@eskimo.com (Steve Summit)
  4. Subject: Re: why arrays may seem like pointers
  5. X-Nntp-Posting-Host: eskimo.com
  6. Message-ID: <DnLLD6.6C3@eskimo.com>
  7. Sender: news@eskimo.com (News User Id)
  8. Organization: schmorganization
  9. References: <313318b8.53776146@nntp.ix.netcom.com> <DnHyrp.CF8@eskimo.com> <MlB_x9_SMUE45Cwf9Q@transarc.com>
  10. Date: Fri, 1 Mar 1996 16:48:41 GMT
  11.  
  12. In article <MlB_x9_SMUE45Cwf9Q@transarc.com>, Jim_Mann@transarc.com writes:
  13. > scs@eskimo.com (Steve Summit) writes:
  14. >> I know of at least two reasons why confusion here persists.
  15. > I think there are serveral others, mostly dealing with common methods
  16. > of using arrays and pointers... if I declare (and later allocate)
  17. >    char *foo;
  18. > I can acess elements as foo[3];
  19.  
  20. Indeed.  And this fact suggests that we may be being a bit too
  21. reactive when we jump all over someone who casually mentions that
  22. "a pointer is just like an array" or something.  Probably all of
  23. us have written
  24.  
  25.     char *p = malloc(100);
  26.  
  27. and then treated p as if it were an array; we may say
  28. (informally) that "p is an array of 100 chars"; and we may even
  29. use, instead of "p", a name containing the word "array".  So when
  30. someone says "this pointer is an array," in a context where it's
  31. clear that they mean "this pointer is simulating an array," there
  32. needn't be any argument.  (It is perhaps this misunderstanding
  33. which has caused some unnecessary debate over in a PL/I vs. C
  34. thread.)
  35.  
  36. > For reasons like this, many newer C programmers get to thinking that
  37. > arrays and pointers are pretty much the same thing.
  38.  
  39. Yup.  And, in some ways, they are, or at least, they can
  40. certainly seem to act like each other.  We should always be
  41. careful, then, to insert those little extra words: not "this
  42. pointer is an array" but "this pointer is simulating an array";
  43. not "an array in a value expression is a pointer" but "an array
  44. in a value expression generates a pointer."
  45.  
  46.                     Steve Summit
  47.                     scs@eskimo.com
  48. -- 
  49. The Communications Decency Act within the Telecommunications Act
  50. of 1996 (U.S.) is an annoying, threatening, abusive, indecent,
  51. and obscene piece of legislation which attempts to ban annoying,
  52. threatening, abusive, indecent, or obscene communication.
  53.